SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.DnnProduct_GetAffiliate
	@AffiliateId int,
	@VendorId int,
	@PortalID int
AS

	SELECT	dbo.DnnProduct_Affiliates.AffiliateId,
		dbo.DnnProduct_Affiliates.VendorId,
		dbo.DnnProduct_Affiliates.StartDate,
		dbo.DnnProduct_Affiliates.EndDate,
		dbo.DnnProduct_Affiliates.CPC,
		dbo.DnnProduct_Affiliates.Clicks,
		dbo.DnnProduct_Affiliates.CPA,
		dbo.DnnProduct_Affiliates.Acquisitions
	FROM	dbo.DnnProduct_Affiliates 
	INNER JOIN dbo.DnnProduct_Vendors ON dbo.DnnProduct_Affiliates.VendorId = dbo.DnnProduct_Vendors.VendorId
	WHERE	dbo.DnnProduct_Affiliates.AffiliateId = @AffiliateId
	AND	dbo.DnnProduct_Affiliates.VendorId = @VendorId
	AND	(dbo.DnnProduct_Vendors.PortalId = @PortalID or (dbo.DnnProduct_Vendors.PortalId is null and @PortalID is null))

GO
